package com.example.viewtime

import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.util.Log
import android.widget.LinearLayout
import java.text.SimpleDateFormat
import java.util.*

/**
 * @author robert
 * @date 2017/12/22
 */

class MyViewGroup : LinearLayout {
    companion object {
        val FORMAT = "dd-MMM-yyyy HH:mm:ss:SSS"
        val TAG: String = MyViewGroup::class.java.simpleName
        val formatter: SimpleDateFormat = SimpleDateFormat(FORMAT, Locale.CHINA);
    }

    constructor(context: Context) : super(context) {}

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {}

    var time: Long = 0;
    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        Log.e(TAG, "开始测量" + formatter.format(System.currentTimeMillis()))
        time = System.nanoTime()
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        Log.e(TAG, "结束测量" + formatter.format(System.currentTimeMillis()))
        Log.e(TAG, "测量总时长(ns)" + (System.nanoTime() - time).toString())
    }

    override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
        Log.e(TAG, "开始布局" + formatter.format(System.currentTimeMillis()))
        time = System.nanoTime()
        super.onLayout(changed, l, t, r, b)
        Log.e(TAG, "结束布局" + formatter.format(System.currentTimeMillis()))
        Log.e(TAG, "布局总时长(ns)" + (System.nanoTime() - time).toString())
    }
}
